# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=snapcast
pkgver=0.27.0
pkgrel=4
pkgdesc="Synchronous multi-room audio player"
url="https://github.com/badaix/snapcast"
arch="all"
license="GPL-3.0-or-later"
depends="$pkgname-client $pkgname-server"
makedepends="
	alsa-lib-dev
	avahi-dev
	boost-dev
	cmake
	expat-dev
	flac-dev
	libvorbis-dev
	opus-dev
	samurai
	soxr-dev
	"
pkgusers="$pkgname"
pkggroups="$pkgname audio"
install="$pkgname-client.pre-install $pkgname-server.pre-install"
subpackages="$pkgname-doc $pkgname-client $pkgname-server"
source="$pkgname-$pkgver.tar.gz::https://github.com/badaix/snapcast/archive/refs/tags/v$pkgver.tar.gz
	$pkgname-0001-Fix-build-with-GCC-13.patch::https://github.com/badaix/snapcast/commit/481f08199ca31c60c9a3475f1064e6b06a503d12.patch
	$pkgname-client.initd
	$pkgname-client.confd
	$pkgname-server.initd
	$pkgname-server.confd
	"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DBUILD_WITH_FLAC=ON \
		-DBUILD_WITH_VORBIS=ON \
		-DBUILD_WITH_OPUS=ON \
		-DBUILD_WITH_AVAHI=ON \
		-DBUILD_WITH_PULSE=ON \
		-DBUILD_TESTS=ON
	cmake --build build
}

check() {
	bin/snapcast_test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

client() {
	pkgdesc="$pkgname client"
	depends=

	amove usr/bin/snapclient
	amove usr/share/pixmaps
	install -Dm755 "$srcdir/$subpkgname.initd" \
		"$subpkgdir"/etc/init.d/"$subpkgname"
	install -Dm644 "$srcdir/$subpkgname.confd" \
		"$subpkgdir"/etc/conf.d/"$subpkgname"
}

server() {
	pkgdesc="$pkgname server"
	depends=

	amove usr/bin/snapserver
	amove etc/snapserver.conf
	amove usr/share/snapserver
	install -Dm755 "$srcdir/$subpkgname.initd" \
		"$subpkgdir"/etc/init.d/"$subpkgname"
	install -Dm644 "$srcdir/$subpkgname.confd" \
		"$subpkgdir"/etc/conf.d/"$subpkgname"
}

sha512sums="
fd86f5b0d38bf308eb9cc1f3024676471176355a8cc91ee8c8d2dfe1aa0cde99fc7636133071b50304fe66ea42dee996e0088e013be7fa703f21c5bc2a35cfdd  snapcast-0.27.0.tar.gz
688fabd922ed826103aad750595921336076c8a4f136b59661aaa7227401c0319fae066dc3da9b37d14a50795c4cce3900be08db267be93b632c2976f4495aea  snapcast-0001-Fix-build-with-GCC-13.patch
bc2219f00fa70890be0c12f6fb8da0ac86949f65c1714648d20f6e83a80e075b8482bafd65ebadcc65708f0c488f9655ad2ddd803e5a061973de4132134acbc0  snapcast-client.initd
fa353d7974d3a8b3b22ff009b762c7c4ee318f9f83e22762a9ebf550484b9fc3cc4dffd389b6d756630dc035cb86d5c5643541957785f8bbf71fe4915691c337  snapcast-client.confd
47feaf72d96ccab6996d24619b1d36a89a74e50d402fb6760792ee62d5c2460718324ef8f437ce2be121488f164372c2c0883b9ff0e45d484b5b0e3778d6d99b  snapcast-server.initd
48d494143d044a413b414b32cd8be51d4242234b6d7cb03102914a42b1ea6b1913c2c31b223c23c6be316918e731875149a2505daa03165659d0a1be3ca7e75c  snapcast-server.confd
"
